function UserUsAssTempZf(){
	
	this.InitForm();
	this.InitOrg();
	this.table=this.InitTable();
}

UserUsAssTempZf.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidorgid").val(orgid);
			vUserUsAssTempZf.searchtable();
		},
		width : 250
	});
	return comboboxm;
}

UserUsAssTempZf.prototype.InitForm=function(){
	var form;
    $("#year").val($("#hidyear").val());
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(year)', function (data) { 
    	   $("#hidyear").val(data.value);
    	   form.render('select');   
    	   vUserUsAssTempZf.searchtable();
       });
       form.on('select(quarter)', function (data) { 
    	   $("#hidquarter").val(data.value);
    	   form.render('select');   
    	   vUserUsAssTempZf.searchtable();
       });
      
       
       
       
	   form.render();
	});  
	return form;
}

UserUsAssTempZf.prototype.InitTable = function() {
	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
		table.render({
			elem : '#list'
			,height : $(window).height() - 100
			,url : 'get_list' // 数据接口
			,page : true // 开启分页
			,limit : 40
			,id: 'useruatmapdlist'
			,limits:[20,40,80,100]
			,method:"post"
			,cols : [ [ // 表头
			            {field : 'realname',title : '姓名',width : "7%",align : 'center',fixed: 'left',templet: '#realnameTpl'}
			            , {field : 'cardno',title : '身份证号',width : "15%",align : 'center'}
				        , {field : 'realorgname',title : '实际工作单位',width : "15%",align : 'center'}
			           , {field : 'year',title : '年份',width : "5%",align : 'center'}
			           , {field : 'quarter',title : '季度',width :  "7%",align : 'center'}
			           , {field : 'status',title : '状态',width : "6%",align : 'center'}
			           
			           , {title : '进度',width : "21%",align : 'center',toolbar : '#process'}
			           , {field : 'pskhzhdf',title : '综合得分',width : "7%",align : 'center'}
			           , {title : '特殊事项说明',width : "6%",align : 'center',toolbar : '#operate1'}
			           , {title : '操作',width : "10%",align : 'center',toolbar : '#operate'}
		            ] ]
		    ,request:{
				type:'post'
			}
			,where:{
				year: $("#year").val(),
				quarter:$("#quarter").val()
				,realname:$("#realname").val(),
				orgid:$("#hidorgid").val()
				}
		    ,done: function(res, page, count){
		    	$("[data-field='quarter']").children().each(function(index){ 
		    		var text=$(this).text();
		    		switch(text){
		    		case "1":
		    			$(this).text('第一季度');
		    			break;
		    		case "2":
		    			$(this).text('第二季度');
		    			break;
		    		case "3":
		    			$(this).text('第三季度');
		    			break;
		    		case "4":
		    			$(this).text('第四季度');
		    			break;
		    		}
               })  
               $("[data-field='status']").children().each(function(index){ 
		    		var text=$(this).text();
		    		
		    		switch(text){
		    		case "-1":
		    			$(this).text('未填写');
		    			break;
		    		case "0":
		    			$(this).text('已填写');
		    			break;
		    		case "1":
		    			$(this).text('提交');
		    			break;
		    		case "2":
		    			$(this).text('审核');
		    			break;
		    		case "3":
		    			$(this).text('归档');
		    			break;
		    		case "4":
		    			$(this).text('驳回');
		    			break;
		    		}
             })  
		    }
		    
		});

		
		 //监听工具条
	    table.on('tool(list)', function(obj){
	      var data = obj.data;
	      if(obj.event === 'detail'){
	    	  vUserUATMzpd.ChangeTab(2,data.mzpdid);
	      } else if(obj.event === 'del'){
	        top.mylayui.confirm('确定要删除吗？',{icon: 0}, function(index,dd){
	        	 top.mylayui.close(index);
	        	 vUserUATMzpd.deleteentity(data.mzpdid);
	        });
	      } else if(obj.event === 'edit'){
	    	  vUserUATMzpd.openadd(data.mzpdid,data.userid,data.year,data.quarter);
	      }
	      else if(obj.event === 'add'){
	    	  vUserUATMzpd.openadd(0,data.userid,data.year,data.quarter);
		  }
	      else if(obj.event === 'tijiao'){
	    	  top.mylayui.confirm('提交后不允许修改，确定要提交吗？',{icon: 0}, function(index){
		        	 top.mylayui.close(index);
		        	 vUserUATMzpd.updatestatus(data.mzpdid,1,data.year,data.quarter,data.userid);
		        });
		  }
	      else if(obj.event==='wjsm'){
	    	  vUserUsAssTempZf.openwjsm(obj.data.userid,data.year,data.quarter);
	      }
	      else if(obj.event==='zuofei'){
	    	  vUserUsAssTempZf.userzf(obj.data.userid,data.year,data.quarter);
	      }
	      
	    });

	    
	});
	
	return table;
}

UserUsAssTempZf.prototype.searchtable=function(){
	//vUserUATMzpd.ChangeTab(1);
	var year=$("#year").val();
	var quarter=$('#quarter').val();
	this.table.reload('useruatmapdlist', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {  
	    	year:year,
	    	quarter:quarter,
	    	realname:$("#realname").val(),
	    	orgid:$("#hidorgid").val()
	    }  
	}); 
}


UserUsAssTempZf.prototype.openwjsm=function(userid,year,quarter){

	top.mylayui.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: 0.5,
        area: ['700px', '250px'],
        content: 'common/user_vtdp?userid='+userid+"&year="+year+"&quarter="+quarter
      });

}

UserUsAssTempZf.prototype.userzf=function(userid,year,quarter){
	top.mylayui.confirm('该人员已经填写的数据被认为是作废数据，不再可用，需要重新从自评开始进行本季度的平时考核评价，确定要作废吗？',{icon: 0}, function(index){
		 top.mylayui.close(index);
		 $.ajax({
				type:"POST",
				url:"user_pd_zf",
				data:{userid:userid,year:year,quarter:quarter},
				beforeSend:function(XHR){
					
				},
				success:function(data){
					data=eval('('+data+')');
					if(data.result>0){
						top.mylayui.msg(data.msg, {icon: 1});
						document.location.reload();
					}
					else{
						top.mylayui.msg(data.msg, {icon: 0});
					}
				},
				complete:function(XHR){
					
				},
				error:function(){
					
				}
			});
	})
	
	
}

var vUserUsAssTempZf=null;
$(function(){
	vUserUsAssTempZf=new UserUsAssTempZf();
})